package cn.south.campus.admin.campus.controller;

import cn.south.campus.admin.campus.model.req.PartTimeJobReq;
import cn.south.campus.admin.campus.model.vo.PartTimeJobApplyVo;
import cn.south.campus.admin.campus.model.vo.PartTimeJobVo;
import cn.south.campus.admin.campus.service.PartTimeJobApplyService;
import cn.south.campus.admin.campus.service.PartTimeJobService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 校园兼职表 前端控制器
 * </p>
 *
 * @author chow
 * @since 2025-03-27
 */
@RestController
@RequestMapping("/campus/partTimeJob")
@AllArgsConstructor
public class PartTimeJobController {

    private final PartTimeJobService partTimeJobService;

    private final PartTimeJobApplyService partTimeJobApplyService;

    @GetMapping("pageQuery")
    public Result<IPage<PartTimeJobVo>> pageQuery(PartTimeJobReq req) {
        return Result.success(partTimeJobService.pageQuery(req));
    }

    @GetMapping("queryById/{id}")
    public Result<PartTimeJobVo> queryById(@PathVariable Long id) {
        return Result.success(partTimeJobService.queryById(id));
    }

    @GetMapping("queryApplyList/{jobId}")
    public Result<List<PartTimeJobApplyVo>> queryApplyList(@PathVariable Long jobId) {
        return Result.success(partTimeJobApplyService.queryApplyList(jobId));
    }

    @PutMapping("audit/{id}/{status}")
    public Result<String> audit(@PathVariable Long id, @PathVariable Integer status) {
        partTimeJobApplyService.audit(id, status);
        return Result.success("审核成功");
    }

    @PutMapping("cancel/{id}")
    public Result<String> cancel(@PathVariable Long id) {
        partTimeJobService.cancel(id);
        return Result.success("撤销成功");
    }

    @PostMapping("publish")
    public Result<String> publish(@RequestBody @Valid PartTimeJobVo partTimeJobVo) {
        partTimeJobService.publish(partTimeJobVo);
        return Result.success("发布成功");
    }
    @PutMapping("update")
    public Result<String> update(@RequestBody @Valid PartTimeJobVo partTimeJobVo) {
        partTimeJobService.modify(partTimeJobVo);
        return Result.success("更新成功");
    }
}
